fn main() {
  pub trait Iterator {
    type Item;
    fn next(&mut self) -> Option<Self::Item>;
  }
  struct Counter {
    current: i32,
    end: i32
  }

  impl Iterator for Counter {
    type Item =  i32;
    fn next(&mut self) -> Option<Self::Item> {
      if self.current < self.end {
        let result = self.current;
        self.current += 1;
        return Some(result);
      }
      return None;
    }
  }

  impl Counter {
    fn new (current: i32, end: i32) -> Self {
      Counter {
        current,
        end
      }
    }
  }

  let mut counter = Counter::new(0, 10);
  counter.next();
  counter.next();
  counter.next();
  let next_res = counter.next();
  // 可以使用match来获取some中的值
  match next_res {
    Some(value) => println!("Next value is {}", value),
    None => println!("No more values")
  }
  // 也可以使用unwrap
  println!("Counter end is {}", next_res.unwrap());
}